﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.Master
{
    public partial class MasterPageIframeStatistics : System.Web.UI.Page
    {
        IList<Area> listArea;
        protected void Page_Load(object sender, EventArgs e)
        {
            
                if (!string.IsNullOrEmpty(this.link.Value))
                {
                    bangdingCompany(int.Parse(this.link.Value));
                }
                else
                {
                    bangdingCompany(1);
                }
            


        }

        /// <summary>
        /// 绑定企业
        /// </summary>
        private void bangdingCompany(int type)
        {
            DataTable dt = new DataTable();
            int i=0;
            switch (type)
            {
                case 1:
                    HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
                    string aredID = "";
                    if (!CurrentAccount.GetUser().Org.Area.AreaID.Equals(Constants.CURRENT_DEPLOY_AREAID))
                    {
                        aredID = CurrentAccount.GetUser().Org.Area.AreaID;
                    }
                    if (string.IsNullOrEmpty(txtHosName.Text))
                    {
                        dt = pre.GetHospital("", aredID, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out i);
                    }
                    else
                    {
                        dt = pre.GetHospital(txtHosName.Text, aredID, 1, 0, out i);
                    }
                    AspNetPager1.RecordCount = i;
                    this.Label1.Visible = true;
                    this.txtHosName.Visible = true;
                    this.benQuaryHos.Visible = true;
                    gvwAreaName.Visible = false;
                    gvwSortName.Visible = false;
                    gvwHospitalName.Visible = true;
                    gvwHospitalName.DataSource = dt;
                    gvwHospitalName.DataBind();

                    break;
                case 2:
                    HZ.Supervise.IBLL.IBLL_Area area = HZ.Supervise.BLLFactory.IBLL_Area();
                    this.Label1.Visible = false;
                    this.txtHosName.Visible = false;
                    this.benQuaryHos.Visible = false;
                    gvwAreaName.Visible = true;
                    gvwSortName.Visible = false;
                    gvwHospitalName.Visible = false;

                    listArea = area.GetSonAreas(CurrentAccount.GetUser().Org.Area.AreaID, AspNetPager2.CurrentPageIndex, AspNetPager2.PageSize, out i);
                    AspNetPager2.RecordCount = i;
                    gvwAreaName.DataSource = listArea;
                    gvwAreaName.DataBind();
                    break;
                default:
                    HZ.Supervise.IBLL.IBLL_ProcureCatalog pro = HZ.Supervise.BLLFactory.IBLL_ProcureCatalog();
                    dt = pro.GetSort("", AspNetPager3.CurrentPageIndex, AspNetPager3.PageSize, out i);
                    AspNetPager3.RecordCount = i;
                    this.Label1.Visible = false;
                    this.txtHosName.Visible = false;
                    this.benQuaryHos.Visible = false;
                    gvwAreaName.Visible = false;
                    gvwSortName.Visible = true;
                    gvwHospitalName.Visible = false;
                    gvwSortName.DataSource = dt;
                    gvwSortName.DataBind();
                    break;
            }


        }


        protected void linkHospital_Click(object sender, EventArgs e)
        {
            this.link.Value = "1";
            bangdingCompany(1);
        }

        protected void linkArea_Click(object sender, EventArgs e)
        {
            this.link.Value = "2";
            bangdingCompany(2);
        }

        protected void LinkType_Click(object sender, EventArgs e)
        {
            this.link.Value = "3";
            bangdingCompany(3);
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bangdingCompany(1);
        }
        protected void AspNetPager2_PageChanged(object sender, EventArgs e)
        {
            bangdingCompany(2);

        }
        protected void AspNetPager3_PageChanged(object sender, EventArgs e)
        {
            bangdingCompany(3);
        }
     

        protected void benQuaryHos_Click(object sender, EventArgs e)
        {
            bangdingCompany(1);
        }

        

    }
}
